//
//  SQRectificationViewController.m
//  energy
//
//  Created by 周曼迪 on 2021/7/8.
//

#import "SQRectificationViewController.h"

#import "SQRectificationModel.h"

#import "SQRectificationDetailsViewController.h"

@interface SQRectificationViewController ()<BaseTableVCInterface>

@end

@implementation SQRectificationViewController

- (void)viewDidLoad {
    self.tableViewInterface = self;
    [super viewDidLoad];
    
    self.navigationItem.title = @"隐患整改";
    
    [self getRectificationData];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getRectificationData];
    }];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getRectificationData) name:@"rectificationDetails" object:nil];
    
    LC_WEAK_SELF
    self.cellTitleIndex = ^(NSString * str, int key) {
        SQRectificationModelData * dataModel = weakSelf.dataSouece[key];
        if ([str isEqualToString:@"confirm"]) {
            SQRectificationDetailsViewController * rectificationDetailsVC = SQRectificationDetailsViewController.new;
            rectificationDetailsVC.type = @"2";
            rectificationDetailsVC.hd_id = dataModel.hd_id;
            [weakSelf pushVC:rectificationDetailsVC];
            
        }else if ([str isEqualToString:@"look"]){
            SQRectificationDetailsViewController * rectificationDetailsVC = SQRectificationDetailsViewController.new;
            rectificationDetailsVC.type = @"1";
            rectificationDetailsVC.hd_id = dataModel.hd_id;
            [weakSelf pushVC:rectificationDetailsVC];
            
        }
          
    };

}


-(void)getRectificationData{
    [SQRectificationModel getDataWithParams:@{@"hd_rectification_person_id":UID,@"hd_enterprise":MEnterpriseId} WithCallBack:^(SQRectificationModel * data) {
        [self detailModelwithArr:data.data withCallBack:nil];
        [self reloadTableView];
        
    }];
}

-(NSInteger)rowsCount:(NSInteger)section{
    return self.dataSouece.count;
}

-(BaseModel *)modelForCell:(NSIndexPath *)indexPath{
    return self.dataSouece[indexPath.row];
}


- (NSArray<NSArray<NSString *> *> *)classArr{
    NSMutableArray *arr = @[].mutableCopy;
    
    for (SQRectificationModelData * dataModel in self.dataSouece) {
        if ([dataModel.hd_acceptance_remarks isEqualToString:@""]) {
           [arr addObject:@"SQConfirmTableViewCell"];
            
    }else if (![dataModel.hd_acceptance_remarks isEqualToString:@""]){
    
            [arr addObject:@"SQRectificationTableViewCell"];
        }
    }
    
    
    return @[arr.copy];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
